package net.wanho.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.wanho.dto.TransshipmentDTO;
import net.wanho.mapper.TransshipmentMapper;
import net.wanho.po.Transshipment;
import net.wanho.service.TransshipmentService;
import net.wanho.vo.PageInfo;
import net.wanho.vo.TransshipmentVo;
import org.springframework.stereotype.Service;

/**
* @author Administrator
* @description 针对表【transshipment(调货单表)】的数据库操作Service实现
* @createDate 2025-04-28 11:41:58
*/
@Service
public class TransshipmentServiceImpl extends ServiceImpl<TransshipmentMapper, Transshipment>
    implements TransshipmentService{

    @Override
    public PageInfo<TransshipmentVo> transshipmentPageList(Integer pageNum, Integer pageSize, TransshipmentDTO transshipmentDTO) {
        Page<TransshipmentVo> page = new Page<>(pageNum, pageSize);
        QueryWrapper<TransshipmentVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(!ObjectUtil.isEmpty(transshipmentDTO.getSourceStoreId()), "source_store_id", transshipmentDTO.getSourceStoreId());
        queryWrapper.eq(!ObjectUtil.isEmpty(transshipmentDTO.getTargetStoreId()), "target_store_id", transshipmentDTO.getTargetStoreId());
        queryWrapper.like(!ObjectUtil.isEmpty(transshipmentDTO.getSourceProductName()), "source_product_name", transshipmentDTO.getSourceProductName());
        queryWrapper.like(!ObjectUtil.isEmpty(transshipmentDTO.getTargetProductName()), "target_product_name", transshipmentDTO.getTargetProductName());
        queryWrapper.like(!ObjectUtil.isEmpty(transshipmentDTO.getCreateName()), "create_name", transshipmentDTO.getCreateName());
        Page<TransshipmentVo> p = baseMapper.selectListByPage(page, queryWrapper);
        PageInfo<TransshipmentVo> pageInfo = new PageInfo<>();
        pageInfo.setPageNum(page.getCurrent());
        pageInfo.setPageSize(page.getSize());
        pageInfo.setTotalNum(page.getTotal());
        pageInfo.setPageCount(page.getPages());
        pageInfo.setLimitIndex(page.offset());
        pageInfo.setResultList(p.getRecords());
        return pageInfo;

    }
}




